#pragma once
#include <iostream>
#include <string>
#include <pthread.h>
namespace xyl
{

    class Mutex
    {
    public:
        Mutex(pthread_mutex_t *pmutex) : _pmutex(pmutex)
        {
        }
        void lock()
        {
            pthread_mutex_lock(_pmutex);
        }
        void unlock()
        {
            pthread_mutex_unlock(_pmutex);
        }

    private:
        pthread_mutex_t *_pmutex;
    };

    class lock_guard
    {
    public:
        lock_guard(pthread_mutex_t *pmutex)
            : _mutex(pmutex)
        {
            _mutex.lock();
        }
        ~lock_guard()
        {
            _mutex.unlock();
        }

    private:
        Mutex _mutex;
    };
}